package chapters15_bingfa.chapters15_3;

/**
 * Created by xinxuchu on 2020/1/29.
 * 多线程同时开始的情况，这个类就是起到同时开始信号的作用
 */
public class FireFlag {

    private volatile boolean fired = false;

    //子线程应该调用waitForFire()等待枪响，而主线程应该调用fire()发射比赛开始信号
    public synchronized void waitForFired() throws InterruptedException{
        while (!fired){
            wait();
        }
    }

    public synchronized void fire(){
        this.fired = true;
        notifyAll();
    }
}
